<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<import type="js" file="js.jquery" />
<import type="js" file="js.jquery#form" />
<import type="js" file="js.common" />
<import type="css" file="css.global" />
<import type="css" file="css.form" />
</head>
<body>
<div class="search"><b>新建用户</b><span style="float:right;margin-right:20px;"><input value="同步考勤机系统用户信息" title="同步考勤机人员信息与OA系统用户信息" class="button" onclick="tongbu()" ></span></div>
<div id="form">
	<form name="form1" action="__APP__/User/insert" method="post" onsubmit="return CheckForm();">
	<table>
		<tr>
			<td class="titlename">用户编号：</td>
			<td><input type="text" name="user_id" maxlength="4" >
			<font color="red">填写用户编号之前请根据姓名查看用户编号，否则考勤信息将无法正常显示</font></td>
		</tr>
		<tr>
			<td class="titlename">姓名：</td>
			<td><input type="text" name="name" >&nbsp;&nbsp;
			<input type="button" value="查看用户编号" class="button" onclick="my_note()" title="如果没有找到对应的用户和编号信息，请点击上面的“同步考勤机人员信息与OA系统用户信息”按钮，同步之后如果还没有找到，请联系考勤机管理员查看是否有该人员信息">
		</tr>
		<tr>
			<td class="titlename">用户名：</td>
			<td><input type="text" name="user_name" >&nbsp;<span class="userwarning"></span></td>
		</tr>
		<tr>
			<td class="titlename">登录密码：</td>
			<td><input type="password" name="password" maxlength="16" size="21" ></td>
		</tr>
		<tr>
			<td class="titlename">确认密码：</td>
			<td><input type="password" name="compassword" maxlength="16" size="21" ></td>
		</tr>
		<tr>
			<td class="titlename">Email：</td>
			<td><input type="text" name="email" size="30"><font color="red">只能填写一个常用邮箱或者公司邮箱，用于发送邮件</font></td>
		</tr>
		<tr>
			<td class="titlename">人员类型：</td>
			<td>
				<select name="type">
					<option value="0" >其他
					<option value="1" >销售
					<option value="2" >技术
					<option value="3" >研发
					<option value="4" >商务
					<option value="5" >行政
					<option value="6" >财务
					<option value="7" >人事
				</select>
			</td>
		</tr>
		<tr>
			<td class="titlename">所属部门：</td>
			<td>
			<volist name="data_dept" id="vo" >
				<div style="width: 130px; float: left;"><label><input type="radio" name="dept_id" value="{$vo.id}" >{$vo.dept_name}</label></div>
			</volist>
			</td>
		</tr>
		<tr>
			<td class="titlename">其他部门：</td>
			<td>
			<volist name="data_dept" id="vo" >
				<div style="width: 130px; float: left;"><label><input type="checkbox" name="dept_aid_id[]" value="{$vo.id}" >{$vo.dept_name}</label></div>
			</volist>
			</td>
		</tr>
		<tr>
			<td class="titlename">工作职位：</td>
			<td><input type="text" name="job" ></td>
		</tr>
		<tr>
			<td class="titlename">职级：</td>
			<td><input type="text" name="rank" ></td>
		</tr>
		<tr>
			<td class="titlename">角色：</td>
			<td>
			<volist name="data_priv" id="vo" >
				<div style="width: 130px; float: left;"><label><input type="radio" name="priv_id" value="{$vo.id}" >{$vo.priv_name}</label></div>
			</volist>
			</td>
		</tr>
		<tr>
			<td class="titlename">辅助角色：</td>
			<td>
			<volist name="data_priv" id="vo" >
				<div style="width: 130px; float: left;"><label><input type="checkbox" name="priv_aid_id[]" value="{$vo.id}" >{$vo.priv_name}</label></div>
			</volist>
			</td>
		</tr>
		<tr>
			<td class="titlename">是否在职：</td>
			<td>
				<div style="width: 130px; float: left;"><label><input type="radio" name="status" value="1" checked >在职</label></div>
				<div style="width: 130px; float: left;"><label><input type="radio" name="status" value="0" >离职</label></div>
			</td>
		</tr>
		<tr>
			<td class="titlename">备注：</td>
			<td><textarea name="remark" cols="40" rows="4"></textarea></td>
		</tr>
		<tr>
			<td class="titlename"></td>
			<td>
				<input type="submit" value="保存" class="submit">&nbsp;&nbsp;
				<input type="button" value="返回" class="button" onclick="back()">
			</td>
		</tr>
	</table>
	</form>
</div>
</body>
<script type="text/javascript">
var UserIDWarning = "用户编号ID为空会导致该用户的考勤数据统计不到，是否继续？";
var NameWarning = "姓名不能为空并且只能是中文汉字！";
var UserNameWarning = "用户名不能为空并且只能是英文字母或数字的组合！";
var PasswordWarning = "登录密码不能为空！";
var ConPassWarning = "确认密码必须和登录密码相同！";
var EmailWarning = "邮箱不能为空，格式必须正确！";
var DeptWarning = "用户部门必须选择！";
var PrivWarning = "用户角色必须选择！";
var StatusWarning = "用户状态必须选择！";

$(document).ready(function(){
	$("input[name='user_name']").blur(function(){
		var user_name = $("input[name='user_name']").val();
		if( user_name == '' ){
			$(".userwarning").html("");
		}else if( !/^[a-z0-9]*$/.test(user_name) ){
			$(".userwarning").html("<font color='red'>"+UserNameWarning+"</font>");
		}else{
			$.get("__APP__/User/check_user_name?user_name="+user_name, function(result){
				$(".userwarning").html(result);
			});
		}
	});
});
function CheckForm(){
	var user_id = $("input[name='user_id']").val()
	if( user_id == "" ){ 
		if(!confirm(UserIDWarning)){
			return true;
		}
	}else if(!/^[0-9]*$/.test(user_id)){
		alert("用户编号只能是数字！");return false;
	}
	
	
	var name = $("input[name='name']").val();
	if( name == '' || !/.*[\u4e00-\u9fa5]+$/.test(name) ){
		alert(NameWarning);return false;
	}
	var user_name = $("input[name='user_name']").val();
	if( user_name == '' || !/^[a-z0-9]*$/.test(user_name) ){
		alert(UserNameWarning);return false;
	}
	var password = $("input[name='password']").val();
	if( password == '' ){
		alert(PasswordWarning);return false;
	}
	var compassword = $("input[name='compassword']").val();
	if( compassword != password ){
		alert(ConPassWarning);return false;
	}
	var email = $("input[name='email']").val();
	if( !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email) || email == ''){
		alert(EmailWarning);return false;
	}
	var dept_id = $("input[name='dept_id'][checked]").val();
	if(dept_id == ''){ alert(DeptWarning);return false; }
	var priv_id = $("input[name='priv_id'][checked]").val();
	if(priv_id == ''){ alert(PrivWarning);return false; }
	var status = $("input[name='status'][checked]").val();
	if(status == ''){ alert(StatusWarning);return false; }
}

function tongbu(){
	$.post("__APP__/User/tongbu",function(result){
		alert(result);
	});
}
function my_note()
{
  var name=$("input[name='name']").val();
  if( name =="" || !/.*[\u4e00-\u9fa5]+$/.test(name) ){
	  alert(NameWarning);return false;
  }
  my_left=document.body.scrollLeft+event.clientX-event.offsetX+50;
  my_top=document.body.scrollTop+event.clientY-event.offsetY+150;

  window.open("__APP__/User/select_user?name="+name,"note_win"+name,"height=150,width=250,status=0,toolbar=no,menubar=no,location=no,scrollbars=auto,top="+ my_top +",left="+ my_left +",resizable=no");
}
</script>
</html>